package com.prs.crm.domain.purchase;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.FlowCodeEntity;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.stock.PurchaseType;
import com.prs.crm.domain.stock.Supplier;

/**
 * @author 兰小刚
 * @version 创建时间：2010-7-1 上午10:21:28 类说明
 */
@Entity
@Table(name = "purchase_purchaseOrder")
public class PurchaseOrder extends FlowCodeEntity {

	private static final long serialVersionUID = -4867503240956693033L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	/**
	 * 采购主题
	 */
	private String purchaseTile;

	/**
	 * 采购编号
	 */
	private String purchaseCode;
	/**
	 * 供应商
	 */
	@ManyToOne
	private Supplier supplier;
	/**
	 * 采购分类
	 */
	@ManyToOne
	private PurchaseType purchaseType;
	/**
	 * 采购日期
	 */
	private Date purchaseDate;
	/**
	 * 我方代表
	 */
	@ManyToOne
	private Person principal;
	/**
	 * 对方代表
	 */
	private String oppositePerson;
	/**
	 * 采购明细
	 */
	@OneToMany(mappedBy = "purchaseOrder")
	@OrderBy
	@Cascade( { org.hibernate.annotations.CascadeType.ALL,
			org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<PurchaseOrderDetail> details;

	/**
	 * 采购概要
	 */
	@Lob
	private String purchaseRemark;

	/**
	 * 采购单状态
	 * 
	 * @return
	 */
	@Column(columnDefinition = "Integer(11) default '0'")
	private int purchaseState;

	/**
	 * 入库状态
	 * 
	 * @return
	 */
	@Column(columnDefinition = "Integer(11) default '0'")
	private int purStoreState;

	/**
	 * 付款状态
	 * 
	 * @return
	 */
	@Column(columnDefinition = "Integer(11) default '0'")
	private int purPayState;
	/**
	 * 真正已付款
	 */
	@Column(columnDefinition = "double(250,3) default '0.000'")
	private Double payedMoney;

	/**
	 * 退回给款
	 */
	@Column(columnDefinition = "double(250,3) default '0.000'")
	private Double returnMoney;
	/**
	 * 联系放系
	 */
	private String message;
	/**
	 * 附件地址
	 * 
	 */
	private String purchaseOrderAttach;
	/**
	 * 
	 * 退货状态0为完成1已完成
	 */
	@Column(columnDefinition = "Integer(11) default '0'")
	private int returenState;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getPurchaseTile() {
		return purchaseTile;
	}

	public void setPurchaseTile(String purchaseTile) {
		this.purchaseTile = purchaseTile;
	}

	public String getPurchaseCode() {
		return purchaseCode;
	}

	public void setPurchaseCode(String purchaseCode) {
		this.purchaseCode = purchaseCode;
	}

	public Supplier getSupplier() {
		return supplier;
	}

	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}

	public PurchaseType getPurchaseType() {
		return purchaseType;
	}

	public void setPurchaseType(PurchaseType purchaseType) {
		this.purchaseType = purchaseType;
	}

	public Date getPurchaseDate() {
		return purchaseDate;
	}

	public void setPurchaseDate(Date purchaseDate) {
		this.purchaseDate = purchaseDate;
	}

	public Person getPrincipal() {
		return principal;
	}

	public void setPrincipal(Person principal) {
		this.principal = principal;
	}

	public String getOppositePerson() {
		return oppositePerson;
	}

	public void setOppositePerson(String oppositePerson) {
		this.oppositePerson = oppositePerson;
	}

	public Set<PurchaseOrderDetail> getDetails() {
		return details;
	}

	public void setDetails(Set<PurchaseOrderDetail> details) {
		this.details = details;
	}

	public String getPurchaseRemark() {
		return purchaseRemark;
	}

	public void setPurchaseRemark(String purchaseRemark) {
		this.purchaseRemark = purchaseRemark;
	}

	public void addDetail(PurchaseOrderDetail detail) {
		if (details == null)
			details = new HashSet<PurchaseOrderDetail>();
		detail.setPurchaseOrder(this);
		details.add(detail);
	}

	public int getPurchaseState() {
		return purchaseState;
	}

	public void setPurchaseState(int purchaseState) {
		this.purchaseState = purchaseState;
	}

	public int getPurStoreState() {
		return purStoreState;
	}

	public void setPurStoreState(int purStoreState) {
		this.purStoreState = purStoreState;
	}

	public int getPurPayState() {
		return purPayState;
	}

	public void setPurPayState(int purPayState) {
		this.purPayState = purPayState;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getPurchaseOrderAttach() {
		return purchaseOrderAttach;
	}

	public void setPurchaseOrderAttach(String purchaseOrderAttach) {
		this.purchaseOrderAttach = purchaseOrderAttach;
	}

	public int getReturenState() {
		return returenState;
	}

	public void setReturenState(int returenState) {
		this.returenState = returenState;
	}

	public Double getPayedMoney() {
		return payedMoney;
	}

	public void setPayedMoney(Double payedMoney) {
		this.payedMoney = payedMoney;
	}

	public Double getReturnMoney() {
		return returnMoney;
	}

	public void setReturnMoney(Double returnMoney) {
		this.returnMoney = returnMoney;
	}

}
